package com.dpad.telematicsclientapp.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

import com.dpad.telematicsclientapp.android.R
import com.dpad.telematicsclientapp.mvp.kit.Kits
import com.dpad.telematicsclientapp.util.utils.Constant.*
import com.dpad.telematicsclientapp.util.utils.DateUtil
import com.dpad.telematicsclientapp.netlibrary.newapp.entity.Result
/**
 * ================================================
 * 作    者：booob
 * 版    本：1.0
 * 创建日期：2019-04-15-0015 13:55
 * 描    述：
 * 修订历史：
 * ================================================
 */
class OutMessageAdapter(data: List<Result>?) : BaseQuickAdapter<Result, BaseViewHolder>(R.layout.item_message_out, data) {

    override fun convert(helper: BaseViewHolder?, item: Result?) {
//        helper?.getView<EasySwipeMenuLayout>(R.id.esm)?.resetStatus()
        helper?.setText(R.id.message_content_tv, if (!Kits.Empty.check(item?.title)) item?.title else "暂无消息")
        helper?.setText(R.id.message_time_tv, if (!Kits.Empty.check(item?.createDate)) Kits.Date.getYmdhm(DateUtil.formatTime(item?.createDate)).replace("-", "/").replace("日", "") else "")
        helper?.addOnClickListener(R.id.ll_item_msg_content)?.addOnClickListener(R.id.tv_item_msg_delet)
        setImageAndTextByType(item?.type, helper?.getView(R.id.message_title_tv), helper?.getView(R.id.message_im))
        if (item != null) {
            val textView: TextView = helper!!.getView<TextView>(R.id.message_count_tv)
            if (item.num > 0) {
                textView.visibility = View.VISIBLE
                textView.text = item.num.toString()
            } else {
                textView.visibility = View.GONE
            }
        }
    }

    private fun setImageAndTextByType(type: String?, titleTv: TextView?, messageIm: ImageView?) {
        when (type) {
            MESSAGESETTING_SYSTEM -> {
                titleTv?.text = "系统通知"
                messageIm?.setImageResource(R.mipmap.sys_message_im)
            }
            MESSAGESETTING_ORRDER -> {
                titleTv?.text = "维保预约"
                messageIm?.setImageResource(R.mipmap.wb_message_im)
            }
            MESSAGESETTING_RESCUE -> {
                titleTv?.text = "救援服务"
                messageIm?.setImageResource(R.mipmap.jy_message_im)
            }
            MESSAGESETTING_ACTIVE -> {
                titleTv?.text = "最新活动"
                messageIm?.setImageResource(R.mipmap.ac_message_im)
            }
            MESSAGESETTING_DZWL -> {
                titleTv?.text = "电子围栏提醒"
                messageIm?.setImageResource(R.mipmap.dz_message_im)
            }
            MESSAGESETTING_ZZFW -> {
                titleTv?.text = "商城服务助手"
                messageIm?.setImageResource(R.mipmap.zz_message_im)
            }
            MESSAGESETTING_YCKZ -> {
                titleTv?.text = "远控提醒"
                messageIm?.setImageResource(R.mipmap.yk_message_im)
            }
        }
    }


}